package wms2010.gui.views.ageClass;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import org.springframework.stereotype.Component;

import wms2010.model.controller.model.AgeClass;
import wms2010.model.controller.model.Discipline;

@Component
public class DisciplineViewTableModel extends AbstractTableModel {
	private List<Discipline> disciplines = new ArrayList<Discipline>();

	public List<Discipline> getDisciplines() {
		return disciplines;
	}

	public void addDiscipline(Discipline discipline) {
		if (!this.disciplines.contains(discipline)) {
			this.disciplines.add(discipline);
			this.fireTableRowsInserted(this.getRowCount() - 1, this
					.getRowCount() - 1);
		}
	}

	public void removeDiscipline(Discipline discipline) {
		int row = this.disciplines.indexOf(discipline);
		if (row != -1) {
			this.disciplines.remove(discipline);
			this.fireTableRowsDeleted(row, row);
		}
	}

	public void setDisciplines(List<Discipline> disciplines) {
		this.disciplines = disciplines;
		System.out.println("set disciplines");
		this.fireTableDataChanged();
	}

	public String getColumnName(int col) {
		switch (col) {
		case 0:
			return "Name";
		case 1:
			return "Description";
		default:
			return "";
		}
	}

	public int getColumnCount() {
		return 2;
	}

	public int getRowCount() {
		return disciplines.size();
	}

	public Object getValueAt(int arg0, int arg1) {
		Discipline discipline = disciplines.get(arg0);
		switch (arg1) {
		case 0:
			return discipline.getName();
		case 1:
			return discipline.getDescription();
		default:
			return "";
		}
	}

}
